package com.huawei.translate;

import com.huawei.translate.conifg.Config;
import com.huawei.translate.util.HttpUtil;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.log4j.Logger;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class RefreshMsAccessTokenJob implements IJob {

    Logger log = Logger.getLogger(RefreshMsAccessTokenJob.class);

    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        try {
            String uri = Config.getTranslateApi() + "/api/translates/token";
            log.info("uri:" + uri);

            CloseableHttpResponse response = HttpUtil.sendPost(uri);

            if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                log.info("Refresh Error!!");
            }
        } catch (Exception e) {
            log.info("Refresh Exception!!");
        }

    }
}
